package com.netty.controller;

import com.alibaba.fastjson.JSON;
import com.netty.client.MyClient;
import com.netty.model.UserDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value ="push")
public class PushController {

    @Autowired
    MyClient nettyClient;

    @GetMapping("/{name}")
    public ResponseEntity pushMsg(@PathVariable String name){

        UserDto userDto = new UserDto();
        userDto.setName(name);
        userDto.setType("1");
        nettyClient.sendMsg(JSON.toJSONString(userDto));
        return new ResponseEntity("请求成功", HttpStatus.OK);
    }
}
